package com.tdam2011.grupo02.ui;

import com.tdam2011.grupo02.R;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

public class MyAlertDialogFragment extends DialogFragment {

	private static OnClickDialogFragmentInterface onClick;

	public static MyAlertDialogFragment newInstance(
			OnClickDialogFragmentInterface onClickInterface, String title,
			String message) {
		onClick = onClickInterface;
		MyAlertDialogFragment frag = new MyAlertDialogFragment();

		Bundle args = new Bundle();
		args.putString("title", title);
		args.putString("message", message);

		frag.setArguments(args);

		return frag;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		String title = getArguments().getString("title");
		String message = getArguments().getString("message");

		return new AlertDialog.Builder(getActivity())
				.setIcon(android.R.drawable.ic_dialog_alert)
				.setTitle(title)
				.setMessage(message)
				.setPositiveButton(getString(R.string.alertBtnOk),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								onClick.doPositiveClick();
							}
						})
				.setNegativeButton(getString(R.string.alertBtnCancel),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								onClick.doNegativeClick();
							}
						}).create();
	}
}
